home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / program / ctutor.exe / SOURCE / READTEXT.C < prev    next >
C/C++ Source or Header  |  1994-05-15  |  612b  |  43 lines

  1.                             /* Chapter 10 - Program 4 - READTEXT.C */
  2. #include "stdio.h"
  3.  
  4. void main()
  5. {
  6. FILE *fp1;
  7. char oneword[100];
  8. char c;
  9.  
  10.    fp1 = fopen("TENLINES.TXT", "r");
  11.  
  12.    do {
  13.       c = fscanf(fp1, "%s", oneword); /* get one word from file    */
  14.       printf("%s\n", oneword);        /* display it on the monitor */
  15.    } while (c != EOF);                /* repeat until EOF          */
  16.  
  17.    fclose(fp1);
  18. }
  19.  
  20.  
  21.  
  22. /* Result of execution
  23.  
  24. This
  25. is
  26. an
  27. example
  28. line.
  29. Line
  30. number
  31. 1
  32. This
  33. is
  34. an
  35.  ... (Many other lines) ...
  36. Additional
  37. lines.
  38. Additional
  39. lines.
  40. lines.
  41.  
  42. */
  43.